package com.test;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Session;

import com.group1.model.AnswerItem;
import com.group1.model.Question;
import com.group1.util.SessionFactoryUtil;

public class testAnswer {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		Session session = SessionFactoryUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
	//	createAnswer(session);
	//	updateAnswer(session);
	//	deleteAnswer(session);
		getAnswer(session);
		session.getTransaction().commit();
	}
	
	public static void getAnswer(Session session)
	{
		//List<AnswerItem> list = AnswerItem.getAllAnswByQuestion(4, session);
		List<AnswerItem> list = new ArrayList<AnswerItem>();
		list.add(AnswerItem.getAnswById(5, session));	
		for (AnswerItem a : list) {
			System.out.print("ID: " + a.getAnsiId() + ", QuestID: " + a.question.questionId);
		}
	}
	
	public static void createAnswer(Session session)
	{
		AnswerItem a = new AnswerItem();
		a.setQuestion(Question.getQuestionByID(4, session));
		a.setAnsiDesc("New Description");
		a.setAnsiValue("Value 3");
		a.setAnsiIsSolution(false);
		session.save(a);
	}
	
	public static void updateAnswer(Session session)
	{
		AnswerItem a = AnswerItem.getAnswById(6, session);
		a.setAnsiIsSolution(true);
		session.saveOrUpdate(a);
		
	}
	
	public static void deleteAnswer(Session session)
	{
		session.delete(AnswerItem.getAnswById(6, session));
		
	}

}
